<?php
session_start(); 
include("../sql/connexionmysql.php");

$numpage = intval($_POST['Page']);

//ici on calcule le nombre de photo sur la page:
$nb = 1;
$sql = 'SELECT * FROM galerie ';
if (intval($_POST['idChaineHotel']) != 0)
	$sql .= 'WHERE idChaineHotel = '. intval($_POST['idChaineHotel']);
if (intval($_POST['idHotel']) != 0)
	$sql .= 'WHERE idHotel = '. intval($_POST['idHotel']);
	
$PatrimoineListe = mysql_query($sql);

$total = mysql_num_rows($PatrimoineListe);
$img = 1;
while ( $Patrimoine = mysql_fetch_array($PatrimoineListe))
{
if ( ($numpage-1)*16 < $img && $nb < 16)
	$nb ++;
$img ++;
}
if ($nb % 4 != 0) $add = 1; else $add = 0;
$ligne =(int)($nb / 4) + $add;
if (preg_match("#MSIE#", $_SERVER["HTTP_USER_AGENT"]))
	$IE = 1;
else $IE = 0;



$_SESSION['idChaineHotel'] = intval($_POST['idChaineHotel']);
?>


		<?php 
		$img = 1;
		$sql = 'SELECT * FROM galerie ';
		if (intval($_POST['idChaineHotel']) != 0)
			$sql .= 'WHERE idChaineHotel = '. intval($_POST['idChaineHotel']);
		if (intval($_POST['idHotel']) != 0)
			$sql .= 'WHERE idHotel = '. intval($_POST['idHotel']);
		$sql .= ' ORDER BY idgalerie ';
		$PatrimoineListe = mysql_query($sql);
		
		$j=0;
		$total = mysql_num_rows($PatrimoineListe);
		while ( $Patrimoine = mysql_fetch_array($PatrimoineListe)) 
		{
			if ( ($numpage-1)*16 < $img && $img <= 16*$numpage)
			{
			?>
			<a href="index.php?page=Zoom&amp;id=<?php echo $Patrimoine['idGalerie']?>">
			<img style="position:absolute; top: <?php echo (110*(int)(($j)/4))?>px; left: <?php echo (110*(($j)%4))?>px;" src="./images/Photos_Patrimoine/Min<?php echo $Patrimoine['LienImage']?>" title="<?php echo htmlentities(stripslashes($Patrimoine['Titre']))?>"  height="110" width="110" />
			</a>
			<?php $j++;
			
			}
			$img ++;
		}
		?>

	<div style="position:absolute; top: <?php echo $ligne*110+20; ?>px; color:rgb(170,170,170);">
	<?php
	if ($total == 0)
		echo 'Aucune photo n\'est associ&eacute;e &agrave; cette chaine d\'hotel.';
	$i = 1;
	while ($i * 16 < $total+16 )
	{
		?>
		<span >
		<a onClick="update_galerie(<? echo $i ?>, <? echo $_SESSION['idChaineHotel'];?>, <? echo $_POST['idHotel']?>);" style="cursor:pointer;<?php if ( $i == $numpage){echo 'color: rgb(126,186,87)';} else echo 'color: rgb(170,170,170)'; ?>">
		<?php echo $i;?></a>		
		<?php if (($i+1) * 16 < $total + 16) echo ' - ';?>
		</span>
		
		<?php 
		$i++;
	}
	?>
	</div>